home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
apps
/
375
/
cal_cnt
/
cal_cnt.lst
next >
Wrap
File List
|
1988-11-17
|
14KB
|
421 lines
' ############################################################################
' ############################################################################
' ############################# CALORIE COUNTER ############################
' ####################### BY RON & KATHY SCHAEFER MDs ######################
' ############################# Published by ############################
' ############################# ST Log 1/89 ############################
' ############################################################################
' ############################################################################
If Xbios(4)=0 Then
Alert 3,"SORRY WORKS IN HIGH & MEDIUM|RESOLUTION ONLY",1,"BYE",Dummy
Edit
Endif
Rez%=Xbios(4) ! Check resolution 0=low 1=med 2=high
If Xbios(4)=2 Then
Tf%=7 ! Correction faction factor for text size
Endif
Dim Spalette%(16,3)
@Save_pal ! Save current pallet
@Setcolors ! Set program screen colors
@Introscreen ! Do title screen
Do
At$="Calorie Counter|By Ron & Kathy Schaefer M.D.s|(C) 1988 Schaefer SuperGraphics|"
At$=At$+"Published by ST Log"
Alert 0,At$,1,"Count|Help|Quit",Dummy
Exit If Dummy=3
If Dummy=1 Then
@Calcount
Cls
Endif
If Dummy=2 Then
@Help
Endif
Loop
@Restorepal ! Restore original palet at end of prgram
Edit
' ----------------------- HELP SUBROUTINE --------------------------------
Procedure Help
Titlew 1," HELP "
Deftext 1,0,0,6+Tf%
Openw 1 ! if using 3.0 use this instead OPENW 1,0,19
Fullw 1
Clearw 1
Print At(1,2);
Print " To use the Calorie Counter just load in the expandable data base"
Print " of food items called CALORIES.DAT, this is done automatically if"
Print " the file is in the same directory as the program CAL_CNT.PRG"
Print
Print " Now enter in the number of calories that you want to plan your"
Print " meal or day for. This will serve as a Goal diet."
Print
Print " Once the food items have been loaded just click on the items"
Print " that you want added up. Click with the left button to add,"
Print " and with the right button to subtract an item. As you plan"
Print " your menu, try and approximate the Goal or Ideal diet."
Print
Print " You can print out a list of the selected foods to take with"
Print " you to store by clicking on LIST at the bottom of the screen."
Print
Print " Ideal American Diet: % of total calories"
Print " ============================================="
Print " Protein 12%"
Print " Fats 30%"
Print " Carbohydrates 58%"
Print " hit return to continue";
Void=Inp(2)
Closew 1
Return
' ---------------------- MAIN CALORIE COUNT SUBROUTINE ----------------
Procedure Calcount
K=0
If Not Openfile! ! If the file has not been opend do so
Path$=Dir$(0)
Filename$=Path$+"\CALORIE.DAT"
If Not Exist(Filename$) Then
Fileselect "*.DAT","CALORIE.DAT",Filename$
Endif
Endif
If Filename$<>"" Then
Titlew 1," Calorie Counter and Menu Planner "
Openw 1 ! if using 3.0 use this instead OPENW 1,0,19
Fullw 1
Graphmode 1
Clearw 1
Deftext 1,0
If Not Openfile! Then
Print
Print
Print " Opening the file ";Filename$
Print " Reading in calorie data on item:";
Color 1
Box 139,13*Rez%,467,35*Rez%
Box 136,11*Rez%,470,37*Rez%
Open "I",#1,Filename$
Openfile!=True
Input #1,T% ! Read in number of food items and DIM arrays
Dim N$(T%),Cals(T%),Fats(T%),Carbos(T%),Prots(T%),Quant(T%)
Do
Inc Nt%
Print At(54,4);Nt%
Input #1,N$(Nt%),Cals(Nt%),Prots(Nt%),Fats(Nt%),Carbos(Nt%)
Exit If Eof(#1)
Loop
Close #1
Else
For N%=1 To T%
Quant(N%)=0
Next N%
Caltotal=0
Prottotal=0
Carbototal=0
Fattotal=0
Endif
Print At(21,10);"Enter the number of calories to be"
Print At(21,11);"your goal: ";
Color 1
Box 154,68*Rez%,445,92*Rez%
Box 151,66*Rez%,448,94*Rez%
Input "",Gcaltotal
Clearw 1
Defmouse 6
Deftext 2
@Initmenuplaner
' ******* main loop *********
Do
If Mx>475 And My>157*Rez% And K=1 Then
@Do_sound_1(5,4)
Endif
Exit If Mx>475 And My>157*Rez% And K=1
Showm
Mouse Mx,My,K
If K>0 Then
If My>35*Rez% And My<153*Rez% Then
@Do_sound_2(9,7)
Endif
If My>159*Rez% Then
@Do_sound_1(3,4)
Endif
If My>35*Rez% And My<153*Rez% Then ! Find which item mouse is over
If Rez%=1 Then
L%=Int((My-35)/8)+1
Else
L%=Int(((My-35)/8)/Rez%)-1
Endif
If K=1 And L%+F%<=T% Then
Inc Quant(L%+F%) ! Add food item
Add Caltotal,Cals(L%+F%)
Add Fattotal,Fats(L%+F%)
Add Prottotal,Prots(L%+F%)
Add Carbototal,Carbos(L%+F%)
Endif
If K=2 And L%+F%<=T% Then
Dec Quant(L%+F%) ! Subtract food item
If Quant(L%+F%)<0 Then
Quant(L%+F%)=0
Else
Sub Caltotal,Cals(L%+F%)
Sub Fattotal,Fats(L%+F%)
Sub Prottotal,Prots(L%+F%)
Sub Carbototal,Carbos(L%+F%)
Endif
Endif
If L%+F%<=T% Then
If Quant(L%+F%)=0 Then
Deftext 1,0
Else
Deftext 2,1 ! If the quantity is >0 highlight that item
Endif
Print At(2,4+L%);N$(L%+F%);" "
Print At(30,4+L%);Cals(L%+F%);" "
Print At(40,4+L%);Fats(L%+F%);" "
Print At(50,4+L%);Carbos(L%+F%);" "
Print At(60,4+L%);Prots(L%+F%);" "
Print At(70,4+L%);Quant(L%+F%);" "
Endif
Deftext 3,0
Print At(2,3);"TOTAL";
Print At(30,3);Caltotal;" "
Print At(40,3);Int(Fattotal);" "
Print At(50,3);Int(Carbototal);" "
Print At(60,3);Int(Prottotal);" "
Print At(66,3);"Quantity"
Deftext 1
Endif
If Mx<154 And My>157*Rez% Then
Add F%,15
If F%>T% Then
Sub F%,15
Endif
For N%=1 To 15
If (N%+F%)<=T% Then
If Quant(N%+F%)=0 Then
Deftext 1,0
Else
Deftext 2,1 ! If the quantity is >0 highlight that item
Endif
Print At(2,4+N%);N$(N%+F%);" "
Print At(30,4+N%);Cals(N%+F%);" "
Print At(40,4+N%);Fats(N%+F%);" "
Print At(50,4+N%);Carbos(N%+F%);" "
Print At(60,4+N%);Prots(N%+F%);" "
Print At(70,4+N%);Quant(N%+F%);" "
Else
Print Space$(72)
Endif
Next N%
Deftext ,0
Endif
If Mx>154 And Mx<321 And My>157*Rez% Then
Add F%,-15
If F%<0 Then
F%=0
Endif
For N%=1 To 15
If Quant(N%+F%)>0 Then
Deftext 2,1 ! If the quantity is >0 highlight that item
Else
Deftext 1,0
Endif
Print At(2,4+N%);N$(N%+F%);" "
Print At(30,4+N%);Cals(N%+F%);" "
Print At(40,4+N%);Fats(N%+F%);" "
Print At(50,4+N%);Carbos(N%+F%);" "
Print At(60,4+N%);Prots(N%+F%);" "
Print At(70,4+N%);Quant(N%+F%);" "
Next N%
Deftext ,0
Endif
If Mx>321 And Mx<475 And My>157*Rez% Then ! LIST routine
Clearw 1
At$="Where do you want the menu|list to be printed?"
Alert 2,At$,1," Screen | Printer ",Pr
@Do_sound_2(4,4)
Defmouse 6
If Pr=1 Then
Deftext 1
Tx$=" Menu Listing Calories Fat Carbo "
Print At(2,2);Tx$+"Protein Quantity"
Print At(1,3);String$(72,"=")
Ln%=0
For N%=1 To T%
If Quant(N%)>0 Then
Print At(2,4+Ln%);N$(N%);" "
Print At(30,4+Ln%);Cals(N%);" "
Print At(40,4+Ln%);Fats(N%);" "
Print At(50,4+Ln%);Carbos(N%);" "
Print At(60,4+Ln%);Prots(N%);" "
Print At(70,4+Ln%);Quant(N%);" "
' Print At(2,3+Ln%);N$(N%),Cals(N%),Quant(N%)
Inc Ln%
If Ln%>15 Then
Ln%=0
Print At(55,21);"Click to continue."
Do
K=Mousek
Exit If K>0
Loop
Clearw 1
Tx$=" Menu Listing Calories Fat Carbo "
Print At(2,2);Tx$;"Protein Quantity"
Print At(1,3);String$(72,"=")
Endif
Endif
Next N%
Print String$(72,"=")
Deftext 3
Print At(2,5+Ln%);"TOTAL";
Print At(30,5+Ln%);Caltotal;" "
Print At(40,5+Ln%);Int(Fattotal);" "
Print At(50,5+Ln%);Int(Carbototal);" "
Print At(60,5+Ln%);Int(Prottotal);" "
Deftext 2
Print At(55,21);"Click to continue."
Deftext 1
Do
K=Mousek
Exit If K>0
Loop
Clearw 1
Else ! Print out list of items on the printer
Sd=10
Tx$=" Menu Listing Calories Grams Grams "
Lprint Tx$;"Grams Quantity"
Lprint Space$(35);"Fat Carbo Protein"
Lprint String$(72,"=")
For N%=1 To T%
If Quant(N%)>0 Then
Lprint N$(N%);Space$(27-Len(N$(N%)));
Lprint Cals(N%);Space$(Sd-Len(Str$(Cals(N%))));
Lprint Fats(N%);Space$(Sd-Len(Str$(Fats(N%))));
Lprint Carbos(N%);Space$(Sd-Len(Str$(Carbos(N%))));
Lprint Prots(N%);Space$(Sd-Len(Str$(Prots(N%))));
Lprint Quant(N%)
Endif
Next N%
Lprint String$(72,"=")
Lprint " TOTAL";Space$(20);
Lprint Caltotal;Space$(Sd-Len(Str$(Caltotal)));
Lprint Fattotal;Space$(Sd-Len(Str$(Fattotal)));
Lprint Carbototal;Space$(Sd-Len(Str$(Carbototal)));
Lprint Prottotal;Space$(Sd-Len(Str$(Prottotal)))
Endif
Ln%=0
F%=0
@Initmenuplaner
Endif
Endif
Loop
Clearw 1
Closew 1
Deftext 1
Endif
Return
' ################# set up and draw first screen for menu planner #########
Procedure Initmenuplaner
Deftext 2
Print " Calories Fat Carbo Protein"
Deftext 3
Print At(2,2);"GOAL";
Print At(30,2);Gcaltotal
Print At(40,2);Int(Gcaltotal*0.3/9)
Print At(50,2);Int(Gcaltotal*0.58/4)
Print At(60,2);Int(Gcaltotal*0.12/4)
Print At(2,3);"TOTAL";
Print At(30,3);Caltotal
Print At(40,3);Fattotal
Print At(50,3);Carbototal
Print At(60,3);Prottotal
Print At(66,3);"Quantity"
Deftext 1
Print String$(72,"=")
Print At(1,20);String$(72,"=")
Deftext 3
Print At(7,21);"NEXT PAGE"
Print At(27,21);"LAST PAGE LIST QUIT"
For N%=1 To 15
If Quant(N%+F%)>0 Then
Deftext 2,1
Else
Deftext 1,0
Endif
Print At(2,4+N%);N$(N%+F%);" "
Print At(30,4+N%);Cals(N%+F%);" "
Print At(40,4+N%);Fats(N%+F%);" "
Print At(50,4+N%);Carbos(N%+F%);" "
Print At(60,4+N%);Prots(N%+F%);" "
Print At(70,4+N%);Quant(N%+F%);" "
Next N%
Color 0
Return
' --------------------- CLICKING SOUND SUBROUINTES ------------
Procedure Do_sound_1(Snd,Snd1)
Sound 1,12,Snd,Snd1
Wave 1,1,9,6000
Return
Procedure Do_sound_2(Snd,Snd1)
Sound 1,12,Snd,Snd1
Wave 1,1,8,512,5
Wave 0,0
Return
Procedure Do_sound_3(Snd,Snd1,Per,Dur)
Sound 1,2,Snd,Snd1
Wave 1,1,9,Per,Dur
Return
' --------------------------- SET SCREEN COLORS -------------------
Procedure Setcolors
Setcolor 2,0,7,7
Setcolor 0,0,0,0
Setcolor 3,7,7,7
Setcolor 1,7,0,2
Return
' ------------- SAVE ORIGINAL COLOR PALETTE -----------------------
Procedure Save_pal
For Z%=0 To 15
Dpoke Contrl,26
Dpoke Contrl+2,0
Dpoke Contrl+6,2
Dpoke Intin,Z%
Dpoke Intin+2,0
Vdisys
Spalette%(Z%,0)=Dpeek(Intout+2)
Spalette%(Z%,1)=Dpeek(Intout+4)
Spalette%(Z%,2)=Dpeek(Intout+6)
Next Z%
Return
Procedure Restorepal
' --------------------- RESTORES PALLET -------------------
For Z%=0 To 15
Dpoke Contrl,14
Dpoke Contrl+2,0
Dpoke Contrl+6,4
Dpoke Intin,Z%
Dpoke Intin+2,Spalette%(Z%,0)
Dpoke Intin+4,Spalette%(Z%,1)
Dpoke Intin+6,Spalette%(Z%,2)
Vdisys
Next Z%
Return
' ------------------------ DO INTRO TITLE SCREEN ---------------------
Procedure Introscreen
For Zz=1 To 12
Deftext 3,0,0,Zz
@Do_sound_1(1,Zz/2)
Text 160,30*Rez%,"Calorie Counter"
Pause 3
Next Zz
For Zz=1 To 12
Deftext 2,0,0,Zz
@Do_sound_1(1,Zz/2)
Text 80,48*Rez%,"by Ron & Kathy Schaefer M.D.s"
Pause 3
Next Zz
For Zz=1 To 12
Deftext 1,0,0,Zz
@Do_sound_1(1,Zz/2)
Text 125,66*Rez%,"Brought to You by ST Log"
Pause 3
Next Zz
Deftext 1,0,0,6+Tf%
Pause 10
Return